<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Method reference</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch25.html" title="Chapter 25. PDF417 (2D-Barcode)"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Method reference</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 25. PDF417 (2D-Barcode)</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Method reference"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2602315"></a>Method reference</h2></div></div></div>
        
        <div class="sect2" title="Encoder methods"><div class="titlepage"><div><div><h3 class="title"><a name="id2602322"></a>Encoder methods</h3></div></div></div>
            
            <p>All encoder methods are accessed on an instance of <code class="code">class
                    PDF417Barcode</code>
            </p>
            <p>
                </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">...
$encoder = new PDF417Barcode($columns,$errlevel);
...</span></pre></td></tr></table></div><p>
            </p>
            <div class="sect3" title="PDF417Barcode"><div class="titlepage"><div><div><h4 class="title"><a name="id2602345"></a>PDF417Barcode</h4></div></div></div>
                
                <p><code class="code">PDF417Barcode($aNumCols=10, $aErrLevel=2)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>To create a new PDF417 encoder with a chosen number of columns and error
                    level. Please note that these parameters can also be adjusted using the methods
                    described below. The method will throw exceptions if the parmeters are outside
                    there valid range.</p>
                <p><code class="code">$aNumCols</code> , an integer in the range [2,30]</p>
                <p><code class="code">$aErrLevel</code>, an integer in the range [0,8]</p>
                <p><span class="bold"><strong>Returns:</strong></span></p>
                <p>A new encoder which is used by the backend to generate the barcode
                    label.</p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Create a new encoder with 20 columns
$encoder = new PDF417Barcode(20);</span></pre></td></tr></table></div><p>
                </p>
            </div>
            <div class="sect3" title="SetColumns"><div class="titlepage"><div><div><h4 class="title"><a name="id2602389"></a>SetColumns</h4></div></div></div>
                
                <p><code class="code">SetColumns($aCols)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Specify number of data columns. This should be a value in the range [2-30]
                    (inclusively) . Note that it is also possible to specify the number of columns
                    in the instantiation of the encoder.</p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Create a new encoder with 20 columns
$encoder = new PDF417Barcode();
$encoder-&gt;SetColumns(20);</span></pre></td></tr></table></div><p>
                </p>
                <p><span class="bold"><strong>Note:</strong></span></p>
                <p>The number of rows will be automatically adjusted to fit the data and the
                    error correction codewords as specified by the error level setting. The number
                    of rows is not directly user configurable.</p>
            </div>
            <div class="sect3" title="SetErrLevel"><div class="titlepage"><div><div><h4 class="title"><a name="id2602416"></a>SetErrLevel</h4></div></div></div>
                
                <p><code class="code">SetErrLevel($aErrLevel)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Specify the chosen level of error correction. </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$encoder = new PDF417Barcode();
$encoder-&gt;SetErrLevel(5);</span></pre></td></tr></table></div><p>
                </p>
                <p><span class="bold"><strong>Note:</strong></span></p>
                <p>A high error level will limit the number of payload data since the total
                    number of data in the label is fixed.</p>
            </div>
            <div class="sect3" title="SetTruncated"><div class="titlepage"><div><div><h4 class="title"><a name="id2602519"></a>SetTruncated</h4></div></div></div>
                
                <p><code class="code">SetTruncated($aTrunc=true)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Specify that barcode should use the truncated PDF format. This will make the
                    barcode slightly narrower and might be used where the physical space is at
                    premium. </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$encoder = new  PDF417Barcode();
$encoder-&gt;SetTruncated ();</span></pre></td></tr></table></div><p>
                </p>
                <p><span class="bold"><strong>Note:</strong></span></p>
                <p>Not all barcode scanners can handle truncated PDF417.</p>
            </div>
        </div>
        <div class="sect2" title="Common backend methods"><div class="titlepage"><div><div><h3 class="title"><a name="id2602572"></a>Common backend methods</h3></div></div></div>
            
            <p>The backend is responsible for the actual output of the barcode (see <a class="xref" href="ch25s03.html#fig.pdf417-encodation-overview" title="Figure 25.4. Overview of the interaction between encoder and backends">Figure 25.4. Overview of the interaction between encoder and backends</a>). </p>
            <p>It is possible to either create an image or a postscript backend. In the creation
                of the backend an instance of the encoder is given as the second argument. The
                actual output from the script (to create the barcode label) is done with a call to
                the <code class="code">Backend::Stroke()</code> method. As usual this call should be the last
                line in the script if it is used to send the image back to the browser. </p>
            <p>The method call to Stroke() should always be guarded with a <code class="code">try{} catch
                    {}</code> statement.</p>
            <p><span class="bold"><strong>Example:</strong></span></p>
            <p>
                </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">try {
    $encoder = new  PDF417Barcode( $columns, $errlevel);
    $backend = PDF417BackendFactory::Create( BACKEND_IMAGE, $encoder);
 
    // .. Output formatting
    $backend-&gt;Stroke();
}
catch(JpGraphException $e) {
    echo 'PDF417 Error: '.$e-&gt;GetMessage();
}</span></pre></td></tr></table></div><p>
            </p>
            <p>In the example above we have chosen to create an image encoder (specified by
                constant <code class="code">BACKEND_IMAGE</code>) by default the image format used will be PNG
                which is also the recommended format.</p>
            <div class="sect3" title="Stroke"><div class="titlepage"><div><div><h4 class="title"><a name="id2602634"></a>Stroke</h4></div></div></div>
                
                <p><code class="code">Stroke($aData, $aFile='')</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Encode a specific data string entered as the first argument and send the
                    barcode output, depending on backend, either directly back to the browser as an
                    image or return the Postscript representation as a string. </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Data to be encoded</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$data</span><span class="hl-code"> = ... ;
 
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    ...
    </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">JpGraphException</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    ...
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
                </p>
            </div>
            <div class="sect3" title="SetVertical"><div class="titlepage"><div><div><h4 class="title"><a name="id2602647"></a>SetVertical</h4></div></div></div>
                
                <p><code class="code">SetVertical($aFlg=true)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Draw the barcode vertically instead of the default horizontal direction</p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$backend-&gt;SetVertical();</span></pre></td></tr></table></div><p>
                </p>
            </div>
            <div class="sect3" title="SetScale"><div class="titlepage"><div><div><h4 class="title"><a name="id2602715"></a>SetScale</h4></div></div></div>
                
                <p><code class="code">SetScale($aScale)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Will arbitrary scale the generated barcode image. Scale factor is specified as
                    a floating point number . </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$backend-&gt;SetScale(2.5);</span></pre></td></tr></table></div><p>
                </p>
            </div>
            <div class="sect3" title="SetModuleWidth"><div class="titlepage"><div><div><h4 class="title"><a name="id2602754"></a>SetModuleWidth</h4></div></div></div>
                
                <p><code class="code">SetModuleWidth($aWidth)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Specifies the module width to be used in the barcode. The module width is
                    interpretated differently depending on whether it is applied on an image or a
                    postscript backend. The module width will determine the physical width of the
                    overall barcode. Please make sure that the printer has good enough resolution to
                    handle the chosen module width. </p>
                <p>For image backends is specifies the number of pixels to be used for the width
                    of one module in the barcode. The module can be thought of as the thinnest line
                    printed in the barcode. Each codeword is encoded 17 modules wide where there are
                    4 black and 4 white separated areas.</p>
                <p>Even though most modern inkjet printers (2003 and later) can resolve modules
                    down to 1 pixels it is recommended that for inkjet printers a module width of &gt;=
                    2 is used. </p>
                <p>For Postcript backend the module width specified the width in Postscript
                    points (1 point = 1/72 inch).</p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$backend-&gt;SetModuleWidth(2);</span></pre></td></tr></table></div><p>
                </p>
                <p>
                    </p><div class="tip" title="Tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Tip</h3>
                        <p>The size of the barcode image can be fine tuned by applying an overall
                            scaling constant as specified with the method
                            <code class="code">SetScale()</code>.</p>
                    </div><p>
                </p>
            </div>
            <div class="sect3" title="SetHeight"><div class="titlepage"><div><div><h4 class="title"><a name="id2602757"></a>SetHeight</h4></div></div></div>
                
                <p><code class="code">SetHeight($aHeight)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Specified the height to width ratio for the individual rows in the barcode. By
                    default the ratio is 3, which means that the height of the rows in the barcode
                    is 3 times the module width. Most scanners can handle a factor between 2-5. You
                    should very rarely have to change this parameter. </p>
                <p>The ratio is specified as an integer. </p>
                <p>One reason to change this to a smaller value is to make a barcode label take
                    up less vertical space.</p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$backend-&gt;SetHeight(2);</span></pre></td></tr></table></div><p>
                </p>
                <p>
                    </p><div class="caution" title="Caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3>
                        <p>Not all barcode scanners are good at handling very small ratios. This
                            will also make the barcode more susceptible to damages.</p>
                    </div><p>
                </p>
            </div>
            <div class="sect3" title="SetColor"><div class="titlepage"><div><div><h4 class="title"><a name="id2602882"></a>SetColor</h4></div></div></div>
                
                <p><code class="code">SetColor($aFrgColor,$aBkgColor)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Specify the foreground and background color for the barcode. </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$backend-&gt;SetColor( 'black', 'lightyellow');</span></pre></td></tr></table></div><p>
                </p>
            </div>
            <div class="sect3" title="ShowFrame"><div class="titlepage"><div><div><h4 class="title"><a name="id2602930"></a> ShowFrame</h4></div></div></div>
                
                <p><code class="code">ShowFrame($aFlg=true)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Draw a 1 pixel frame around the barcode. This is not recommended in production
                    since it might disturb some scanners reading. This is only useful if you need a
                    visual feedback on the boundaries for the image. </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">backend-&gt;SetFrame();</span></pre></td></tr></table></div><p>
                </p>
            </div>
            <div class="sect3" title="ShowText"><div class="titlepage"><div><div><h4 class="title"><a name="id2602973"></a>ShowText</h4></div></div></div>
                
                <p><code class="code">ShowText($aFlg=true)</code></p>
                <p>
                    </p><div class="caution" title="Caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3>
                        <p>This is an extension specific to JpGraph. Human readable text is not
                            part of the official PDF417 standard and hence this is disabled by
                            default.. There are usually no problems of including this text but it is
                            not recommended to do so in a production environment. This is mostly
                            useful when debugging an application and to make it easer to see that
                            the correct data is encoded as a barcode label.</p>
                    </div><p>
                </p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Show human readable text of the encoded data underneath the barcode label. </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p>%%<p>
                </p>
            </div>
            <div class="sect3" title="SetFont"><div class="titlepage"><div><div><h4 class="title"><a name="id2602917"></a>SetFont</h4></div></div></div>
                
                <p><code class="code">SetFont($aFontFam,$aFontStyle,$aFontSize)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p> Specify the font for the human readable text underneath the barcode label. </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$backend-&gt;SetFont( FF_ARIAL, FS_NORMAL, 8);</span></pre></td></tr></table></div><p>
                </p>
            </div>
        </div>
        <div class="sect2" title="Image backend methods"><div class="titlepage"><div><div><h3 class="title"><a name="id2603037"></a>Image backend methods</h3></div></div></div>
            
            <div class="sect3" title="SetImgFormat"><div class="titlepage"><div><div><h4 class="title"><a name="id2603067"></a> SetImgFormat</h4></div></div></div>
                
                <p><code class="code">SetImgFormat($aFormat)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Specify image format. Possible values are </p>
                <p>
                    </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
                            <p><code class="code">'auto'</code></p>
                        </li><li class="listitem">
                            <p><code class="code">'png'</code></p>
                        </li><li class="listitem">
                            <p><code class="code">'jpeg'</code></p>
                        </li><li class="listitem">
                            <p><code class="code">'gif'</code></p>
                        </li></ul></div><p>
                </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$backend-&gt;SetImgFormat('jpeg');</span></pre></td></tr></table></div><p>
                </p>
            </div>
        </div>
        <div class="sect2" title="Postscript backend methods"><div class="titlepage"><div><div><h3 class="title"><a name="id2603084"></a>Postscript backend methods</h3></div></div></div>
            
            <p></p>
            <div class="sect3" title="SetEPS($aFlg=true)"><div class="titlepage"><div><div><h4 class="title"><a name="id2603155"></a>SetEPS($aFlg=true)</h4></div></div></div>
                
                <p><code class="code">SetEPS($aFlg=true)</code></p>
                <p><span class="bold"><strong>Purpose:</strong></span></p>
                <p>Format the output as Encapsulated Postcript. This adds a bounding box
                    information to the output and makes this format suitable to be included in other
                    postscript files. </p>
                <p><span class="bold"><strong>Example:</strong></span></p>
                <p>
                    </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$encoder = new PDF417Barcode( $columns, $errlevel);
$backend = PDF417BackendFactory::Create( BACKEND_PS, $encoder); 
$backend-&gt;SetEPS();</span></pre></td></tr></table></div><p>
                </p>
            </div>
        </div>
    </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="ch25.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
